﻿using DataImporter.Models;
using SqlSugar;

namespace DataImporter
{
    /// <summary>
    /// 数据库上下文
    /// </summary>
    public class DBContext
    {
        public DBContext()
        {
            Db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = "Data Source=47.104.71.104;Initial Catalog=SXICE;uid=sa;pwd=Ts287146819",
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute
            });
        }

        /// <summary>
        /// 用来处理事务多表查询和复杂的操作
        /// </summary>
        public SqlSugarClient Db;

        /// <summary>
        /// 开始事务
        /// </summary>
        protected void BeginTran()
        {
            Db.BeginTran();
        }

        /// <summary>
        /// 提交事务
        /// </summary>
        protected void CommitTran()
        {
            Db.CommitTran();
        }

        /// <summary>
        /// 回滚事务
        /// </summary>
        protected void RollbackTran()
        {
            Db.RollbackTran();
        }

        /// <summary>
        /// 分类数据操作对象
        /// </summary>
        public SimpleClient<Category> CategoryDB { get { return new SimpleClient<Category>(Db); } }
        /// <summary>
        /// 心脏病意外评估风险模型数据操作对象
        /// </summary>
        public SimpleClient<HDAARM> HDAARMDB { get { return new SimpleClient<HDAARM>(Db); } }
        /// <summary>
        /// 体检项目数据操作对象
        /// </summary>
        public SimpleClient<ExamItem> ExamItemDB { get { return new SimpleClient<ExamItem>(Db); } }
        /// <summary>
        /// 体检项目套餐数据操作对象
        /// </summary>
        public SimpleClient<ExamItemPackage> ExamItemPackageDB { get { return new SimpleClient<ExamItemPackage>(Db); } }
        /// <summary>
        /// 体检项目关系数据操作对象
        /// </summary>
        public SimpleClient<ExamPackageWithItems> ExamItemRelationDB { get { return new SimpleClient<ExamPackageWithItems>(Db); } }
        /// <summary>
        /// CC数据操作对象
        /// </summary>
        public SimpleClient<CC> CCDB => new SimpleClient<CC>(Db);
        /// <summary>
        /// CC风险数据操作对象
        /// </summary>
        public SimpleClient<CCRisk> CCRiskDB => new SimpleClient<CCRisk>(Db);
        /// <summary>
        /// 乳腺癌数据操作对象
        /// </summary>
        public SimpleClient<BC> BCDB => new SimpleClient<BC>(Db);
        /// <summary>
        /// 乳腺癌风险数据操作对象
        /// </summary>
        public SimpleClient<BCRisk> BCRiskDB => new SimpleClient<BCRisk>(Db);
        /// <summary>
        /// 乳腺癌年龄、平均风险数据操作对象
        /// </summary>
        public SimpleClient<BCAgeAverageRisk> BCAgeRisk => new SimpleClient<BCAgeAverageRisk>(Db);
        /// <summary>
        /// LTHR数据操作对象
        /// </summary>
        public SimpleClient<LTHR> LTHRDB => new SimpleClient<LTHR>(Db);
        /// <summary>
        /// LTHRReference数据操作对象
        /// </summary>
        public SimpleClient<LTHRReference> LTHRRenferenceDB => new SimpleClient<LTHRReference>(Db);
        /// <summary>
        /// 糖尿病数据操作对象
        /// </summary>
        public SimpleClient<T2DM> T2DMDB => new SimpleClient<T2DM>(Db);
        /// <summary>
        /// 糖尿病风险指数数据操作对象
        /// </summary>
        public SimpleClient<T2DMRisk> T2DMRiskDB => new SimpleClient<T2DMRisk>(Db);
        /// <summary>
        /// 糖尿病得分表数据操作对象
        /// </summary>
        public SimpleClient<T2DMScores> T2DMScoresDB => new SimpleClient<T2DMScores>(Db);
        /// <summary>
        /// 痛风风险指数数据操作对象
        /// </summary>
        public SimpleClient<GoutRisk> GoutRiskDB => new SimpleClient<GoutRisk>(Db);
        /// <summary>
        /// VA问题数据库操作对象
        /// </summary>
        public SimpleClient<VAQuestion> VAQuestionDB => new SimpleClient<VAQuestion>(Db);
        /// <summary>
        /// VA答案数据库操作对象
        /// </summary>
        public SimpleClient<VAAnswer> VAAnswerDB => new SimpleClient<VAAnswer>(Db);
        /// <summary>
        /// 补充体检库操作对象
        /// </summary>
        public SimpleClient<ReplenishPE> ReplenishPEDB => new SimpleClient<ReplenishPE>(Db);
        /// <summary>
        /// 体检库操作对象
        /// </summary>
        public SimpleClient<PhysicalExaminationItem> PhysicalExaminationItemDB => new SimpleClient<PhysicalExaminationItem>(Db);
    }
}